/*
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
 *
 * Copyright (c) 2013-2014 sagyf Yang. The Four Group.
 */

/**
 * Created by yfyang on 4/12/14.
 */
define([ 'adminapp'], function ($app) {
    // nav menu
    $app.navactive('parking');

    var action_tpl = Handlebars.compile($(g.actiontpl).html());

    var $parking_table = $app.listtable({
        'sAjaxSource' : g.ctx + "admin/parking/list",
        'fnServerParams': function( aoData){
            var sd = $('#search_form').serializeJSON();
            $.each(sd, function(name, val){
                aoData.push({"name": name, "value": val});
            });
        },
        'aoColumns'   : [
            $app.checkall,
            $app.autono,
            {'mDataProp': 'id' },
            {'mDataProp': 'floor' },
            {'mDataProp': 'mark' },
            {'mDataProp': 'area' },
            {'mDataProp': 'description' },
            {'mDataProp': 'location' },
            {'mDataProp': 'mall' }
        ],
        'aoColumnDefs': [
            { 'bSearchable': false, 'bVisible': false, 'aTargets': [ 2, 5, 6, 8] },
            {
                'aTargets': [3],
                'mData'   : null,
                'mRender' : function (data, type, full) {
                    return full['name'];
                }
            },
            {
                'aTargets': [9],
                'mData'   : null,
                'mRender' : function (data, type, full) {
                    return action_tpl(full);
                }
            }
        ]
    }, 'parking-list');

    $('#search_btn').on('click', function (e) {
        e.preventDefault();
        $parking_table.fnReloadAjax();
    });

    return {};
});